package com.mall.filter;


import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Simple filter that prints a report on the standard output each time an
 * associated servlet or JSP page is accessed.
 */

public class CharsetEncodingFilter implements javax.servlet.Filter
{
	String encoding;

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws ServletException, IOException
	{

		HttpServletRequest httpServletRequest = (HttpServletRequest) request;
		HttpServletResponse httpServletResponse =(HttpServletResponse) response;
		httpServletRequest.setCharacterEncoding(encoding);
		httpServletResponse.setCharacterEncoding(encoding);
		chain.doFilter(request, response);

	}

	public void init(FilterConfig config) throws ServletException
	{

		encoding = config.getInitParameter("encoding");
	}

	public void destroy()
	{
	}

}
